<?php 

require_once  __DIR__ . '/includes/authenticate.php';

if( isset($_POST['playerID']) ) { 

  $username = $_SESSION['username'];

  $playerID = $_POST['playerID'];

  include_once __DIR__ . '/db_bb_connect.php';

  require_once __DIR__ . '/includes/BasketbalFunctions.php';

  $basketbalfunctions = new BasketbalFunctions();

  $sql = "SELECT firstname, lastname, type
	FROM users
	WHERE user_key = '$playerID'";

  if ($db->query($sql)) {  
    } else {
      echo "Error: " . $sql . "<br>" . $db->error;
    }

  $result = $db->query($sql);
  $row = $result->fetch_assoc();
  $firstname = $row['firstname']; 
  $lastname = $row['lastname']; 
  $position = $row['type'];
  
  ?>
<div class="container-fluid">

<div class="row">
<div class="col-md-12"> 
	<div id="pagetitle">
  <h2>Home </h2>
  <h4><?= ucwords($position); ?> <?= $firstname; ?> <?= $lastname; ?> </h4>
</div>

<ul class="nav nav-tabs" id="mytab">
  <li class="active"><a data-toggle="tab" href="#teamgoals" class="clicklog" name="teamgoals">Team Goals</a></li>
  <li><a data-toggle="tab" href="#teamactionpoints" class="clicklog" name="teamactionpoints">Team Feedforward</a></li>
  <li><a data-toggle="tab" href="#personalactionpoints" class="clicklog" name="personalactionpoints">Personal Feedforward</a></li>  
  <li><a data-toggle="tab" href="#stats" class="clicklog" name="homestats">Stats</a></li>
  <li><a data-toggle="tab" href="#league" class="clicklog" name="league">League</a></li>
  <li><a data-toggle="tab" href="#calendar" class="clicklog" name="calendar">Calendar</a></li>

  
</ul>

<div class="tab-content" id="mytabcontent">

   <div id="teamgoals" class="tab-pane fade in active">
   
          <div class="container-fluid">
            
            <div class="row">

              <div class="col-md-2 col-lg-3"></div>

              <div class="col-md-8 col-lg-6">

                <?php 

              $filename = $basketbalfunctions->GetLastActiveTeamGoalsFilenameFromPlayerID($playerID); 

              ?>

                <img src="./uploads/teamgoals/<?= $filename ?>" alt=" " width="100%" class="img-responsive center-block" />

 
              </div>
              
              <div class="col-md-2 col-lg-3"></div>

            </div>

          </div>          
    </div>

  <div id="teamactionpoints" class="tab-pane">

          <h3>Video</h3>
          <ul class="nav nav-pills nav-justified">
  <li class="active"><a href="#team_videos" data-toggle="pill">Team Videos</a></li>
  <li><a href="#opponent_videos" data-toggle="pill">Opponent Videos</a></li>
</ul>


<div class="tab-content">
  
  <div id="team_videos" class="tab-pane fade in active">
<?php 

    $basketbalfunctions->ShowTeamVisibleVideoFeedforwardCurrentTeam("team"); ?>
  </div>


  <div id="opponent_videos" class="tab-pane fade">
<?php 

    $basketbalfunctions->ShowTeamVisibleVideoFeedforwardCurrentTeam("opponent"); ?>
  </div>

</div>
          <h3>Other</h3>

 
         <h4>General</h4>
          <ul class="list-group"><?php $basketbalfunctions->ShowAttentionpointsTeam('general', $playerID); ?></ul> 
        <h4>Training</h4>
          <ul class="list-group"><?php $basketbalfunctions->ShowAttentionpointsTeam('training', $playerID); ?></ul>
        <h4>Game</h4>
          <ul class="list-group"><?php $basketbalfunctions->ShowAttentionpointsTeam('game', $playerID); ?></ul>
    </div>

  	<div id="personalactionpoints" class="tab-pane"> 

          <h3>Video</h3>
          <?php 

          $basketbalfunctions->ShowVisibleVideoFeedforwardPlayer(); ?>

          <h3>Other</h3>   

        <h4>General</h4>
          <ul class="list-group"><?php $basketbalfunctions->ShowAttentionpointsPlayer($playerID,'general'); ?></ul> 
        <h4>Training</h4>
          <ul class="list-group"><?php $basketbalfunctions->ShowAttentionpointsPlayer($playerID,'training'); ?></ul>
        <h4>Game</h4>
          <ul class="list-group"><?php $basketbalfunctions->ShowAttentionpointsPlayer($playerID,'game'); ?></ul>

    </div>


	<div id="stats" class="tab-pane">

	<?php 

	$basketbalfunctions->LastGameStatsPlayer($playerID);

	$basketbalfunctions->SeasonGameStatsPlayer($playerID);

	$basketbalfunctions->LastTrainingStatsPlayer($playerID);

	$basketbalfunctions->SeasonTrainingStatsPlayer($playerID);

	?>


	</div>

	<div id="calendar" class="tab-pane">
   
          <div class="container-fluid">
            
            <div class="row">

              <div class="col-sm-7 col-md-7 col-lg-7">
                <h4>Upcoming Games</h4>

                <?php $basketbalfunctions->GetUpcomingGamesFromPlayerID($playerID, 5); ?>
                

              </div>

              <div class="col-sm-5 col-md-5 col-lg-5">
                <h4>Upcoming Birthdays</h4>

                <?php $basketbalfunctions->GetCurrentTeamBirthdaysFromPlayerID($playerID, 5); ?>
                
              </div>

            </div>

          </div>          
    </div>

    <div id="league" class="tab-pane">
   
          <div class="container-fluid">
            
            <div class="row">

                <div class="col-md-1 col-lg-1"></div>

                <div class="col-md-5 col-lg-5">

                  <?php 

                  $teamID = $basketbalfunctions->GetCurrentTeamIDFromPlayerKey($playerID);
                  $season = $basketbalfunctions->GetLastActiveSeasonFromPlayerID($playerID);

                  $basketbalfunctions->GetTeamLeagueStandings($teamID, $season);                  
                      
                  ?>

              </div>
              <div class="col-md-5 col-lg-5">

                  <?php 

                  $basketbalfunctions->GetTeamLeagueAllResults($teamID, $season);
                      
                  ?>

              </div>
              <div class="col-md-1 col-lg-1"></div>
 
            </div>

          </div>          
    </div>



</div>
</div>
</div>
</div>


<script type="text/javascript" src="./js/bootstrap-tabcollapse.js"></script>

<script type="text/javascript">
  
  $('#mytab').tabCollapse();

  $(".clicklog").on("click", function(e){
    e.preventDefault(); 
    var name = $(this).attr("name");
    var username = "<?= $username ?>";
    $.ajax({
        type: "POST",
          url: "./clicklog.php",
          data: { 'name' : name,
              'username' : username
          },
          success: function(data) {    
            console.log(data);
          },
          error: function (xhr, status, error) {
            console.log(xhr.responseText);
          }
      });

  });

</script>


<?php } ?>

